@page "/docio/edit-equation"
@inject Microsoft.JSInterop.IJSRuntime JS
@using System.IO
@using Syncfusion.Blazor.Buttons
@using BlazorDemos.Data.FileFormats.DocIO
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment
@inherits SampleBaseComponent;

<SampleDescription>
    <p style="font-size:16px">This sample demonstrates how to modify a mathematical equation in a Word document using Essential DocIO.</p>
</SampleDescription>
<ActionDescription>
    <p style="font-size:16px">DocIO allows you to modify a mathematical equation in the Word document.</p>
                <p style="font-size:16px">	<ul style="font-size:16px"><li>You can modify the text in the equation field.</li>
				<li>You can change the format of an equation. </li> 
			</ul>
		</p>&nbsp;<p style="font-size:16px">More information about the headers and footers can be found in this <a href="https://help.syncfusion.com/file-formats/docio/working-with-mathematical-equation#modify-existing-equation">documentation</a> section.</p>
</ActionDescription>

    <div class="control-section">
        <p style="font-size:16px">Click the button to view the generated Word document. Please note that Microsoft Word Viewer or Microsoft Word is required to view the resultant Word document.</p>

        <table>
            <tr>
                <td>
                    <h5 class="row" style="font-size:16px">Save As:</h5>
                </td>
                <td>
                    <div class="col-xs-12 col-sm-12 col-lg-1 col-md-6">
                        <SfRadioButton Label="DOCX" Name="DOCX" Value=@("DOCX") @bind-Checked="@documentType"></SfRadioButton>
                    </div>
                </td>
                <td>
                    <div class="col-xs-12 col-sm-12 col-lg-1 col-md-6">
                        <SfRadioButton Label="PDF" Name="PDF" Value=@("PDF") @bind-Checked="@documentType"></SfRadioButton>
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <div class="button-section">
                        <div id="button-control">
                            <div class="row">
                                <div>
                                    <SfButton @onclick="GenerateDocument">Generate Document</SfButton>
                                </div>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </div>

<style>
    .control-section .row {
        margin: 10px 0;
    }
</style>

@code {
    MemoryStream documentStream;
    string documentType = "DOCX";

    /// <summary>
    /// Create and download the simple Word document
    /// </summary>
    public async void GenerateDocument(MouseEventArgs args)
    {
        EditEquationService service = new EditEquationService(hostingEnvironment);
        documentStream = service.EditEquation(documentType);
        if (documentType == "DOCX")
            await JS.SaveAs("EditEquation.docx", documentStream.ToArray());
        else if (documentType == "PDF")
            await JS.SaveAs("EditEquation.pdf", documentStream.ToArray());        
    }
}